package services

import (
	"context"
	"fmt"
)

type ProdService struct {
}

func (this *ProdService) GetProdStock(ctx context.Context, request *ProdRequest) (*ProdResponse, error) {
    return &ProdResponse{ProdStock:20}, nil
}

func (this *ProdService) GetProdStocks(ctx context.Context, request *QuerySize) (*ProdResponseList, error) {
    var pl ProdResponseList
    var i int32
    for i = 1; i <= request.Size; i++ {
        var p = ProdResponse{
            ProdStock:20+i,
        }
        pl.Prodres = append(pl.Prodres, &p)
    }

    return &pl, nil
}

func (this *ProdService) GetProdStock2(ctx context.Context, request2 *ProdRequest2) (*ProdResponse, error) {
    var stock int32 = 0
    if request2.ProdArea == ProdAreas_A { //判断传递过来的枚举值是哪一个再做出相应的判断
        stock = 30
    } else if request2.ProdArea == ProdAreas_B {
        stock = 31
    } else {
        stock = 50
    }
    return &ProdResponse{ProdStock: stock}, nil
}

func (this *ProdService) NewProd(ctx context.Context, request *OrderRequest) (*ProdModel, error) {
    fmt.Println(request.OrderMain)
    return &ProdModel{ProdId:1 ,ProdName:"升级" ,ProdPrice: 34.6}, nil
}


func (this *ProdService) NewOrder(ctx context.Context, request *OrderRequest) (*OrderResponse, error){
    fmt.Println(request.OrderMain)
    err := request.OrderMain.Validate()
    if err != nil {
        return &OrderResponse{Status:"500", Message:err.Error()}, nil
    }
	return &OrderResponse{Status:"200", Message:"成功"}, nil
}
